package org.monkey.common.generator.controller;

import io.swagger.annotations.Api;
import javax.validation.Valid;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.monkey.common.generator.entity.GeneratorConfig;
import org.monkey.common.generator.service.GeneratorApiService;
import org.monkey.request.plugin.entity.TimeAnalyse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Data
@RestController
@Api(value = "/generator", tags = "生成接口")
@RequestMapping("/generator")
@Validated
public class GeneratorApiController {
  @Autowired
  GeneratorApiService generatorApiService;
  @TimeAnalyse
  @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE,consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<FileSystemResource> generator(@Valid@RequestBody GeneratorConfig generatorConfig) {
    return generatorApiService.generator(generatorConfig);
  }
}
